<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>AceDemo</title>
</head>
<style>
    *{
        padding:0px;
        margin:0px;
    }
    html,body,pre{
        height:100%;
    }
</style>
<body>
    <pre id="editor"></pre>
</body>
<script src="./js/ace.min.js"></script>
<!--要更改主题，只需包含主题的JavaScript文件-->
<script src="./js/theme-github.min.js" type="text/javascript" charset="utf-8"></script>
<script src="./js/theme-github_dark.min.js" type="text/javascript" charset="utf-8"></script>
<!--默认情况下，编辑器只支持纯文本模式;许多其他语言作为单独的模块可用。在包含该模式的JavaScript文件后:-->
<script src="./js/mode-java.min.js" type="text/javascript" charset="utf-8"></script>
<script>
    // https://cdnjs.com/libraries/ace

    var editor = ace.edit("editor");
    // 使用主题:
    // editor.setTheme("ace/theme/github");
    editor.setTheme("ace/theme/github_dark");
    // 使用该模式
    editor.session.setMode("ace/mode/java");

    //字体大小
    editor.setFontSize(14);
    //设置只读（true时只读，用于展示代码）
    editor.setReadOnly(false);
    //自动换行,设置为off关闭
    editor.setOption("wrap", "free")
    editor.setOptions({
        enableBasicAutocompletion: true,
        enableSnippets: true,
        enableLiveAutocompletion: true,
        showPrintMargin: false, //打印边距
    });
    // 设置内容
    editor.setValue(`package com.lcf.common.model;

/**
 * @author ChenFei
 * @date 2021/10/25
 */
public interface Constant {

    String SUCCESS = "success";

    String ERROR = "error";

    int SUCCESS_CODE = 200;

    int ERROR_CODE = 500;
}`,1);
    // editor.setValue("text2", -1); // set value and move cursor to the start of the text
    // editor.session.setValue("the new text here"); // set value and reset undo history
    var codeValue = editor.getValue(); // or session.getValue
    console.log(codeValue);
</script>
</html>